package org.example.exception;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 不知道如何处理的，手动 throw new RuntimeException(e); -- 但最终最上层还是要统一处理
 * RuntimeException是unchecked异常的父类，不需要catch处理，如IndexOutOfBoundsException、NullPointerException
 */

public class UnCheckedException {

    public static int createCheckedException(){
        try {
            throw new IllegalAccessException("CheckedException");
        } catch (IllegalAccessException e) {
            throw new RuntimeException("IllegalAccessException(\"CheckedException\")");
        }
    }

    public static int createUnCheckedException(){
        // java.lang.ArithmeticException: / by zero
        return 1/0;
    }

    public static String createUnCheckedException2(){
        List<String> list =new ArrayList<>();
        return list.get(0);
        //下标溢出: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    }

    public static String createUnCheckedException3(){
        Map<String,String> map=new HashMap<>();
        return map.get("test");
    }

}

